package com.ysh.contentcenter.controller;

import com.ysh.contentcenter.domain.dto.content.ShareDTO;
import com.ysh.contentcenter.service.content.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shares")
public class ShareController {
    @Resource
    private ShareService shareService;

    // 使用DiscoveryClient来查询服务中的实列对象
    @Resource
    private DiscoveryClient discoveryClient;


    @GetMapping("/{id}")
    public ShareDTO findById(@PathVariable Integer id){
        return this.shareService.findById(id);
    }


    @GetMapping("/test")
    public List<ServiceInstance> getInstances(){
        return this.discoveryClient.getInstances("user-center");
    }


}
